import React from 'react';
import { Routes, Route } from 'react-router-dom';
import AdminLayout from '../layouts/AdminLayout';
import Dashboard from '../pages/admin/Dashboard';
import UserManagement from '../pages/admin/UserManagement';
import UserDetails from '../pages/admin/UserDetails';
import UserDetail from '../pages/admin/UserDetail';
import ContentManagement from '../pages/admin/ContentManagement';
import PermissionRoute from '../components/admin/PermissionRoute';
import FaceAnalysisConfig from '../pages/admin/content/FaceAnalysisConfig';
import PalmAnalysisConfig from '../pages/admin/content/PalmAnalysisConfig';
import BaziAnalysisConfig from '../pages/admin/content/BaziAnalysisConfig';
import BaziDatabase from '../pages/admin/content/BaziDatabase';
import DreamKeywordManagement from '../pages/admin/content/DreamKeywordManagement';
import TarotManagement from '../pages/admin/content/TarotManagement';
import VersionManagement from '../pages/admin/VersionManagement';
import SystemSettings from '../pages/admin/SystemSettings';
import FinanceManagement from '../pages/admin/finance/FinanceManagement';
import OperationManagement from '../pages/admin/operation/OperationManagement';

// 管理员路由配置
const AdminRoutes = () => {
  return (
    <Routes>
      <Route path="/" element={<AdminLayout />}>
        {/* 仪表盘路由 - 所有管理员都可以访问 */}
        <Route path="" element={<PermissionRoute permissions={['dashboard_view']} />}>
          <Route index element={<Dashboard />} />
          <Route path="dashboard" element={<Dashboard />} />
        </Route>
        
        {/* 用户管理路由 - 需要用户管理权限 */}
        <Route path="users" element={<PermissionRoute permissions={['users_view']} />}>
          <Route index element={<UserManagement />} />
          <Route path=":userId" element={<UserDetails />} />
          <Route path=":id" element={<UserDetail />} />
        </Route>
        
        {/* 内容管理路由 - 需要相应的内容管理权限 */}
        <Route path="content" element={<PermissionRoute permissions={['content_manage']} />}>
          <Route index element={<ContentManagement />} />
          <Route path="face" element={<PermissionRoute permissions={['face_analysis_config']} />}>
            <Route index element={<FaceAnalysisConfig />} />
          </Route>
          <Route path="palm" element={<PermissionRoute permissions={['palm_analysis_config']} />}>
            <Route index element={<PalmAnalysisConfig />} />
          </Route>
          <Route path="bazi-analysis" element={<PermissionRoute permissions={['bazi_analysis_config']} />}>
            <Route index element={<BaziAnalysisConfig />} />
          </Route>
          <Route path="bazi-database" element={<PermissionRoute permissions={['bazi_analysis_config']} />}>
            <Route index element={<BaziDatabase />} />
          </Route>
          <Route path="dream-keyword" element={<PermissionRoute permissions={['dream_interpretation_config']} />}>
            <Route index element={<DreamKeywordManagement />} />
          </Route>
          <Route path="tarot-management" element={<PermissionRoute permissions={['tarot_card_config']} />}>
            <Route index element={<TarotManagement />} />
          </Route>
        </Route>
        
        {/* 财务管理路由 - 需要财务权限 */}
        <Route path="finance" element={<PermissionRoute permissions={['finance_manage']} />}>
          <Route index element={<FinanceManagement />} />
        </Route>
        
        {/* 运营管理路由 - 需要运营权限 */}
        <Route path="operation" element={<PermissionRoute permissions={['operation_manage']} />}>
          <Route index element={<OperationManagement />} />
        </Route>
        
        {/* 系统管理路由 - 需要特定权限或角色 */}
        <Route path="app-versions" element={<PermissionRoute permissions={['app_version_manage']} />}>
          <Route index element={<VersionManagement />} />
        </Route>
        <Route path="settings" element={<PermissionRoute permissions={['system_settings']} roles={['super_admin']} />}>
          <Route index element={<SystemSettings />} />
        </Route>
      </Route>
    </Routes>
  );
};

export default AdminRoutes;